﻿<?php 
include_once("../function.php");
$name=$_COOKIE['username'];
$sql="select * from ts_user where username='$name'";
$res=mysqli_query($link,$sql);
if(is_object($res))
{
	if(mysqli_num_rows($res)==1)
	{
		$one=mysqli_fetch_assoc($res);
		$a=$one['uid'];
	}
}
$sql="select * from ts_cart where user_id='$a'";
$res=mysqli_query($link,$sql);
if(is_object($res))
{
	if(mysqli_num_rows($res)>0)
	{
		$arr=array();
		while(($list=mysqli_fetch_assoc($res))!=false)
		{
			$arr[]=$list;
		}
	//print_r($arr);//Array ( [0] => Array ( [cart_id] => 53 [color] => #000000 [size] => L [num] => 1 [user_id] => 3 [pid] => 143 ) )
	}
}
//echo $arr[0]['pid'];
$sql="select * from ts_product";
$res=mysqli_query($link,$sql);
if(is_object($res))
{
	if(mysqli_num_rows($res)>0)
	{
		$pro=array();
		while(($list=mysqli_fetch_assoc($res))!=false)
		{
			$pro[]=$list;
		}
		//print_r($pro);
	}
}
//echo $pro[0]['thumb'];
?>
<!doctype html>
<html>
 <head>
  <title>购物车</title>
  <meta charset="utf-8"/>
  <style>
	#big
	{
		width:100%;
		height:1000px;
		border:0px solid red;
	}
	#top
	{
		width:100%;
		height:280px;
		border:0px solid red;
	}
	#middle
	{
		width:100%;
		height:auto;
		border:0px solid red;
	}	
	#tt{width:100%;height:30px;border:0px solid red;}
	.t1{color:#909090;float:left;font-size:1.1em;}
	.t2{color:#909090;float:right;font-size:1.1em;}
	td{font-size:1.3em;font-weight:bold;}
	#dh{width:100%;height:50px;border:0px solid red;background-color:#1F81B0;}

	ul{list-style-type:none;height:50px;}

	ul li{float:left;margin:10px;margin-left:25px;line-height:30px;color:white;}

	li a{text-decoration:none;color:white;}

	.d1{width:100%;height:50px;border:0px solid red;line-height:50px;}
	.d2{margin-left:50px;}
	.m1{font-size:13px;}
	#bottom
	{
		width:100%;
		height:150px;
		border:0px solid red;
	}
	#db{
	width:100%;
	height:50px;
	border:0px solid red;
	line-height:50px;
	}
  p{
	margin-left:43%;
	font-size:15px;
	}
#jy{
	width:100%;
	height:50px;
	border:0px solid red;
	}
.p1{
	margin-left:40%;font-size:10px
	}
.p3{
	float:right;
	margin-right:15px;
	display:inline-block;
	}
#rl{
	width:100%;
	height:10px;
	border:0px solid blue;
	}
a{text-decoration:none;color:black;}
.sy{margin-left:20px;}
  </style>
 </head>

 <body>
<div id="big">
	<div id="top">
		<div id="tt">
			<div class="t1" >
				<span class="sy"><a href="index.php">网站首页</a></span>
				<span class="sy"><a href="index.php">用户中心</a></span>
				<span class="sy"><a href="shopcar.php">我的购物车(0)</a></span>
				<span class="sy"><a href="user_order.php">我的订单(0))</a></span>
			</div>
			<div class="t2">
					<?php if(!isset($_COOKIE["username"])){ ?>
					<a href="./login.php">登录</a>|
					<a href="./regist.php">免费注册</a>|
					<?php }else{?>
					<font size=3 color="#ababab">您好！<?=$_COOKIE["username"]?>，<b>欢迎来到欣才商城！</b>|
					<a href="./out2.php">退出</a></font>
					<?php }?>
			</div>
		</div>
		<hr color="#e3e3e3"/>

		<div>
			<table width="500px" height="30px">
				<tr>
					<td><font color="#4577fc" style="margin-left:50px;">欣才</font></td>
					<td>商城</td>
					<td>
						<input type="text" name="" style="height:30px;"/>
						<input type="submit" name="sub" value="搜索" style="height:35px;" />
					</td>
				</tr>
			</table>
		</div>
		<div id="dh">
			<ul>
				<li><a href="index.php">首页</a></li>
				<li>|</li>
				<li><a href="index.php">商城</a></li>
				<li>|</li>
				<li><a href="">新闻</a></li>
				<li>|</li>
				<li><a href="">活动</a></li>
				<li>|</li>
				<li><a href="">论坛</a></li>
			</ul>
		</div>
		<div class="d1"><font size=4 class="d2" color="#808080">当前所在:商城>购物车</font></div>
		<hr color="#e8e8e8"/>
	</div>

	<div id="middle">
		<div class="m1">
			<table width="100%" height="550px" cellspacing=0 border=0>
			<?php if(isset($arr)&&!empty($arr)) {?>
				<tr style="font-size:17px;">
					<td align="center" colspan=2>图片</td>
					<td align="center">商品名称</td>
					<td>属性</td>
					<td align="center">单价</td>
					<!--<td>小计</td>-->
					<td align="center">数量</td>
					<td colspan=2>操作</td>
				</tr>
				<tr>
					<td colspan=8><hr/></td>
				</tr>
				
				<?php $total=0;if(isset($arr)){
				foreach($arr as $v){
					$sql="select * from ts_product where pid".'='.$v['pid'];
					$res=mysqli_query($link,$sql);
					if(is_object($res))
					{
						if(mysqli_num_rows($res)==1)
							{
								$list=mysqli_fetch_assoc($res);
								$thumb=$list['thumb'];
								$b=$list['pname'];
								$price=($list['price']-$list['sprice'])*$v['num'];
								$sums=$list['snums'];
								//print_r($list);
								$total+=$price;
							}
					
					}?>
					<tr>
						<td align="center"><img src="../<?=$thumb?>" width="100px" height="90px"/></td>
						<td align="center" colspan=2><?=$b?></td>
						<td>
								颜色:<input type="text" name="ys" value="" style="display:inline-block;background:<?=$v['color']?>;width:30px;"/>
								尺寸:<?=$v['size']?>
						</td>
						
						<td align="center">&yen;<?=$price?></td>
						<!--<td><font color="#07bcf8"/>&yen;999</font></td>-->
						<form action="edit.php" method="get">
							<td align="center">
								<a href="./edit_j.php?cart_id=<?=$v['cart_id']?>&num=<?=$v['num']?>&snums=<?=$list['snums']?>">-</a>
								<!--<?php if(isset($arr)){foreach($arr as $vo){?><?php }}?>-->
								<input type="text" value="<?=$v['num']?>" name="number" style="width:50px;"/>
								<a href="edit_add.php?cart_id=<?=$v['cart_id']?>&num=<?=$v['num']?>&snums=<?=$list['snums']?>">+</a>
								<br/>
								<font style="font-size:0.5em;margin-left:15px;">库存:<?=$sums?></font>
							</td>

							<td colspan=2>
								<input type="hidden" name="snums" value="<?=$list['snums']?>"/>
								<input type="hidden" name="cart_id" value="<?=$v['cart_id']?>"/>
								<input type="submit" name="edit" value="修改"/>
								<a href="del_one.php?id=<?=$v['pid']?>" style="color:red">删除</a>
							</td>
						</form>
						<tr>
							<td colspan=8><hr/></td>
						</tr>
					</tr>
				<?php }}?>
				<?php }else{$total=0;?>
				<tr>
					<td colspan=7><h1>购物车空空如也</h1><hr/></td>
				</tr><hr/>	
				<?php }?>
				<tr>
					<td colspan=5>
						<?php
						$sql="select * from ts_user where username='$_COOKIE[username]'";
						$res=mysqli_query($link,$sql);
						$res=mysqli_fetch_assoc($res);
						?>
						<a href="del-all.php?user_id=<?=$res['uid']?>">
						<button class="gwc" style="background-color:#F6F6F6; width:160px; height:45px ;color:black;font-size:28px;">清空购物车</button>
						</a>
					</td>	
					<td>
						<span style="float:right;font-size:25px;">商品总价:
						<font color="#f9c164"/>&yen;<?=$total?></font></span>	
					</td>
				</tr>
				<tr>
					<td colspan=7>
						<a href="index.php"><input type="submit" name="sub" value="继续购物" style="background-color:#F6F6F6; width:150px; height:45px ;color:black;font-size:28px;float:right;margin-right:0px;" /></a>
						<?php if(isset($arr)){?>
						<a href="./order.php?type=2"><input type="submit" name="sub" value="去结算" style="background-color:#6CBDEC; width:150px; height:45px ;color:white;font-size:28px;float:right;margin-right:20px;" /></a>
						<?php }?>
					</td>
				</tr>
			</table>
		</div>
	</div>
	<div id="bottom">
		
		<div id="db">
			<p>关于我们|法律声明|工作机会|联系我们</p>
		</div>
		<div id="jy">
			<p class="p1">Copyright@2013 Thinksite Co.Let night reserved 经营许可证编号：苏A-12345678</p>
		</div>
	
	</div>
</div>
 </body>
</html>